﻿<template>
  <a-card :bordered="false">
    <div class="table-operator">
      
    </div>

    <div class="table-page-search-wrapper">
      <div class="table-page-search-wrapper" style="text-align: right">
        <a-input v-model="queryParam.keyword" style="width: 20%" placeholder="请输入出租人姓名" />

        <a-button
          type="primary"
          icon="search"
          style="margin-left: 8px"
          @click="
            () => {
              this.pagination.current = 1
              this.getDataList()
            }
          "
        >
          搜索
        </a-button>

        <a-button
          icon="search"
          style="margin-left: 8px"
          @click="
            () => {
              if (this.divistrue) {
                this.divistrue = false
              } else {
                this.divistrue = true
              }
            }
          "
          >高级搜索</a-button
        >
        <a-button type="primary" style="margin-left: 8px" :disabled="!hasSelected()" @click="authen(selectedRowKeys)">批量认证</a-button>
        <a-button style="margin-left: 8px" icon="redo" @click="() => (queryParam = {})">重置</a-button>
        <a-button type="primary" style="margin-left: 8px" icon="plus" @click="hanldleUpload()">批量导入</a-button>
        <a-button
          v-if="hasPerm('employee.Delete')"
          type="danger"
          style="margin-left: 8px"
          icon="minus"
          @click="handleDelete(selectedRowKeys)"
          :disabled="!hasSelected()"
          :loading="loading"
          >删除</a-button
        >
        <a-button type="primary" icon="redo" style="margin-left: 8px" @click="getDataList()">刷新</a-button>
      </div>
    </div>

    <a-drawer :width="500" title="高级筛选" placement="top" :visible="divistrue" @close="onClose">
      <a-row>
        <a-col :span="8"
          >出租人姓名&emsp;<a-input v-model="queryParam.keyword" placeholder="请输入出租人姓名" style="width: 80%"></a-input
        ></a-col>
        <a-col :span="8"
          >法人证件号码&emsp;<a-input v-model="queryParam.IdNumber" style="width: 80%" placeholder="请输入法人证件号码"></a-input
        ></a-col>

        <a-col :span="8"
          >银行卡号&emsp;<a-input
            v-model="queryParam.BankCardNo"
            style="width: 80%"
            placeholder="请输入银行卡号"
          ></a-input
        ></a-col>
      </a-row>
      <a-row style="margin-top: 10px">
        <a-col :span="8">
          联系&emsp;电话&emsp;<a-input
            v-model="queryParam.EmpPhone"
            style="width: 80%"
            placeholder="请输入联系电话"
          ></a-input>
        </a-col>
        <a-col :span="8"
          >状&emsp;&emsp;&emsp;&emsp;态&emsp;
          <a-select v-model="queryParam.AuditInf" placeholder="请选择认证状态" style="width: 80%">
            <a-select-option value="">全部数据</a-select-option>
            <a-select-option value="1">已认证</a-select-option>
            <a-select-option value="0">未认证</a-select-option>
          </a-select>
        </a-col>
      </a-row>

      <div style="text-align: right; margin-top: 30px">
        <a-button @click="onClose" icon="close">关闭</a-button>
        <a-button
          type="primary"
          style="margin-left: 8px"
          icon="search"
          @click="
            () => {
              this.pagination.current = 1
              this.getDataList()
              this.divistrue = false
            }
          "
          >查询</a-button
        >
      </div>
    </a-drawer>

    <a-table
      ref="table"
      :columns="columns"
      :dataSource="data"
      :rowKey="row => row.Id"
      :pagination="pagination"
      :loading="loading"
      @change="handleTableChange"
      :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
      :bordered="false"
      size="middle"
    >
      <span slot="action" slot-scope="text, record">
        <template>
          <a @click="handleEdit(record.Id)" v-if="hasPerm('employee.Edit')">编辑</a>
          <a-divider type="vertical" />
          <a-popconfirm
            title="确定删除吗？"
            v-if="hasPerm('employee.Delete')"
            ok-text="确定"
            cancel-text="取消"
            @confirm="handleDelete([record.Id])"
            @cancel="cancel"
          >
            <a href="#">删除</a>
          </a-popconfirm>
          <a-divider type="vertical" />
          <a @click="ViewCar(record.Id)">车辆信息</a>
        </template>
      </span>
      <span slot="IdCardNo1" slot-scope="text,record">
        <template>
        {{projectPrivacy(record.IdCardNo,1)}}
        </template>
      </span>
      <span slot="BankCardNo1" slot-scope="text,record">
        <template>
        {{projectPrivacy(record.BankCardNo,2)}}
        </template>
      </span>
      <span slot="EmpPhone1" slot-scope="text,record">
        <template>
        {{projectPrivacy(record.EmpPhone,2)}}
        </template>
      </span>
      <span slot="AuditInf" slot-scope="text">
        <span v-if="text == '1'"><a-tag color="green">已认证</a-tag></span>
        <span v-else-if="text == '0'"><a-tag color="red">未认证</a-tag></span>
      </span>
    </a-table>

    <edit-form ref="editForm" :parentObj="this"></edit-form>
    <upload1 ref="uploadForm" :parentObj="this"></upload1>


    <a-modal
    title="车辆信息"
    width="70%"
    :visible="Carvisible"
    :confirmLoading="loading"
    @cancel="CarviewCancel">

      <a-table
      ref="table"
      :columns="Carcolumns"
      :dataSource="CarData"
      :rowKey="row => row.Id"
      :loading="loading"
      :bordered="false"
      size="middle"
    >
    <template slot="Status" slot-scope="text">
        <span v-if="text == '1'"><a-tag color="green">已审核</a-tag></span>
        <span v-if="text == '0'"><a-tag color="red">待审核</a-tag></span>
      </template>
      </a-table>
    <template slot="footer">
      <a-button @click="CarviewCancel">关闭</a-button>
    </template>
    </a-modal>
  </a-card>
</template>

<script>
import EditForm from './EditForm'
import upload1 from './employeeUpload'

const columns = [
  { title: '姓名', dataIndex: 'EmpName', width: '10%' },
  { title: '身份证号码', dataIndex: 'IdCardNo', width: '15%', scopedSlots: { customRender: 'IdCardNo1' } },
  { title: '银行卡号', dataIndex: 'BankCardNo', width: '15%', scopedSlots: { customRender: 'BankCardNo1' } },
  { title: '手机号码', dataIndex: 'EmpPhone', width: '13%' , scopedSlots: { customRender: 'EmpPhone1' }},
  { title: '实名状态', dataIndex: 'AuditInf', width: '10%' , scopedSlots: { customRender: 'AuditInf' }},
  { title: '入网时间', dataIndex: 'CreateTime', width: '15%' },
  { title: '操作', dataIndex: 'action', scopedSlots: { customRender: 'action' } },
];
const Carcolumns = [
  { title: '车牌', dataIndex: 'CarNo', width: '20%' },
  { title: '车型', dataIndex: 'CarBrandModel', width: '20%' },
  
  { title: '审核状态', dataIndex: 'Status', width: '20%', scopedSlots: { customRender: 'Status' } },
  { title: '入网时间', dataIndex: 'CreateTime', width: '20%' }
]
export default {
  components: {
    EditForm,
    upload1,
  },
  mounted() {
    this.getDataList()
  },
  data() {
    return {
      divistrue:false,
      CarData:[],
      Carvisible:false,
      data: [],
      pagination: {
        current: 1,
        pageSize: 10,
        showTotal: (total, range) => `总数:${total} 当前:${range[0]}-${range[1]}`,
      },
      filters: {},
      sorter: { field: 'Id', order: 'asc' },
      loading: false,
      columns,
      Carcolumns,
      queryParam: {},
      selectedRowKeys: [],
    }
  },
  methods: {
    onClose() {
      this.divistrue = false
    },
    CarviewCancel(){
      this.Carvisible = false
    },
    //查看车辆信息
    ViewCar(row){
      this.$http.post('/Base_leasesystem_employee/leasesystem_employee/GetEmpCar',{ id: row }).then((res)=>{
        this.CarData = res.Data
      })
      this.Carvisible = true
    },
    handleTableChange(pagination, filters, sorter) {
      this.pagination = { ...pagination }
      this.filters = { ...filters }
      this.sorter = { ...sorter }
      this.getDataList()
    },
    getDataList() {
      this.selectedRowKeys = []

      this.loading = true
      this.$http
        .post('/Base_leasesystem_employee/leasesystem_employee/GetHeightSearch', {
          PageIndex: this.pagination.current,
          PageRows: this.pagination.pageSize,
          SortField: this.sorter.field || 'Id',
          SortType: this.sorter.order,
          Search: this.queryParam,
          ...this.filters,
        })
        .then((resJson) => {
          this.loading = false
          this.data = resJson.Data.Data
          const pagination = { ...this.pagination }
          pagination.total = resJson.Data.Total
          this.pagination = pagination
        })
    },
    onSelectChange(selectedRowKeys) {
      this.selectedRowKeys = selectedRowKeys
    },
    hasSelected() {
      return this.selectedRowKeys.length > 0
    },
    hanldleAdd() {
      this.$refs.editForm.openForm()
    },
    hanldleUpload() {
      this.$refs.uploadForm.openForm()
    },
    handleEdit(id) {
      this.$refs.editForm.openForm(id)
    },
    handleDelete(ids) {
      var thisObj = this

      return new Promise((resolve, reject) => {
        thisObj.$http.post('/Base_leasesystem_employee/leasesystem_employee/DeleteData', ids).then((resJson) => {
          resolve()

          if (resJson.Success) {
            thisObj.$message.success('操作成功!')

            thisObj.getDataList()
          } else {
            thisObj.$message.error(resJson.Msg)
          }
        })
      })
    },
    cancel(e) {
      this.$message.error('已取消删除')
    },
    //格式化表格数据  1 身份证号码  2  银行卡 、 手机号
    projectPrivacy(phone,type) {
      if(type == 1){
        let header = phone.slice(0, 4);
				let footer = phone.slice(-4);
				let projectPhone = header + " **** " + footer;
				return projectPhone;
      }else if(type == 2){
        let header = phone.slice(0, 3);
				let footer = phone.slice(-4);
				let projectPhone = header + " **** " + footer;
				return projectPhone;
      }
				
			},
    //批量认证
    authen(ids){
      this.$http.post('/Base_leasesystem_employee/leasesystem_employee/AuthenEmp',ids).then(res=>{
        console.log(res)
        if(res.Success){
          this.$message.success("认证成功")
          this.getDataList()
        }else{
          this.$message.error("认证失败，请重试")
        }
      })
    }
  },
}
</script>

<style>
.ant-table-thead > tr > th
{
  font-weight: 600;
  color: #333333;
}
</style>